<?php
namespace Xmlib\Filament;

use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Xmlib\Filament\Commands\MakeAdminCommand;

class FilamentServiceProvider extends PackageServiceProvider
{
    public function configurePackage(Package $package): void
    {
        $package->name('xmlib-filament')
            ->hasMigrations([
                'add_username_and_mobile_to_users_table',
                'add_is_admin_to_users_table',
            ])
            ->hasCommand(MakeAdminCommand::class)
            ->hasInstallCommand(function (InstallCommand $command) {
                $command->publishMigrations()
                    ->startWith(function (InstallCommand $command) {
                        $command->info('Starting the installation process...');
                        $command->call('filament:install', ['--panels' => true]);
                    })
                    ->askToRunMigrations()
                    ->endWith(function (InstallCommand $command) {
                        $command->call('google-fonts:fetch');
                        $command->call('make:filament-admin');
                        $command->info('All done!');
                    })
                    ->askToRunMigrations();
            });
    }
}